package com.ruoyi.web.controller.system;

import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TCkPickingwavegoodsBack;
import com.ruoyi.system.service.ITCkPickingwavegoodsBackService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 出库历史查询Controller
 *
 * @author ruoyi
 * @date 2024-09-12
 */
@RestController
@RequestMapping("/system/BACK")
public class TCkPickingwavegoodsBackController extends BaseController
{
    @Autowired
    private ITCkPickingwavegoodsBackService tCkPickingwavegoodsBackService;

    /**
     * 查询出库历史查询列表
     */
    @PreAuthorize("@ss.hasPermi('system:BACK:list')")
    @GetMapping("/first")
    public TableDataInfo first(TCkPickingwavegoodsBack tCkPickingwavegoodsBack)
    {
        LocalDate today=LocalDate.now();
        String endsTime = String.valueOf(today.plusDays(1));
        String  sevenDaysAgo = String.valueOf(today.minus(7, ChronoUnit.DAYS));
        tCkPickingwavegoodsBack.setStartTime(sevenDaysAgo);
        tCkPickingwavegoodsBack.setEndsTime(endsTime);
        startPage();
        List<TCkPickingwavegoodsBack> list = tCkPickingwavegoodsBackService.selectFirstTCkPickingwavegoodsBackList(tCkPickingwavegoodsBack);
        return getDataTable(list);
    }

    /**
     * 查询出库历史查询列表
     */
    @PreAuthorize("@ss.hasPermi('system:BACK:list')")
    @GetMapping("/list")
    public TableDataInfo list(TCkPickingwavegoodsBack tCkPickingwavegoodsBack)
    {
        String[] addTimes = tCkPickingwavegoodsBack.getAddDatas();
        if (addTimes != null && addTimes.length > 1) {
            tCkPickingwavegoodsBack.setStartTime(addTimes[0]);
            tCkPickingwavegoodsBack.setEndsTime(addTimes[1]);
        }
        startPage();
        List<TCkPickingwavegoodsBack> list = tCkPickingwavegoodsBackService.selectTCkPickingwavegoodsBackList(tCkPickingwavegoodsBack);
        return getDataTable(list);
    }

    /**
     * 导出出库历史查询列表
     */
    @PreAuthorize("@ss.hasPermi('system:BACK:export')")
    @Log(title = "出库历史查询", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TCkPickingwavegoodsBack tCkPickingwavegoodsBack)
    {
        List<TCkPickingwavegoodsBack> list = tCkPickingwavegoodsBackService.selectTCkPickingwavegoodsBackList(tCkPickingwavegoodsBack);
        ExcelUtil<TCkPickingwavegoodsBack> util = new ExcelUtil<TCkPickingwavegoodsBack>(TCkPickingwavegoodsBack.class);
        util.exportExcel(response, list, "出库历史查询数据");
    }

    /**
     * 获取出库历史查询详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:BACK:query')")
    @GetMapping(value = "/{PICKINGID}")
    public AjaxResult getInfo(@PathVariable("PICKINGID") String PICKINGID)
    {
        return success(tCkPickingwavegoodsBackService.selectTCkPickingwavegoodsBackByPICKINGID(PICKINGID));
    }

    /**
     * 新增出库历史查询
     */
    @PreAuthorize("@ss.hasPermi('system:BACK:add')")
    @Log(title = "出库历史查询", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TCkPickingwavegoodsBack tCkPickingwavegoodsBack)
    {
        return toAjax(tCkPickingwavegoodsBackService.insertTCkPickingwavegoodsBack(tCkPickingwavegoodsBack));
    }

    /**
     * 修改出库历史查询
     */
    @PreAuthorize("@ss.hasPermi('system:BACK:edit')")
    @Log(title = "出库历史查询", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TCkPickingwavegoodsBack tCkPickingwavegoodsBack)
    {
        return toAjax(tCkPickingwavegoodsBackService.updateTCkPickingwavegoodsBack(tCkPickingwavegoodsBack));
    }

    /**
     * 删除出库历史查询
     */
    @PreAuthorize("@ss.hasPermi('system:BACK:remove')")
    @Log(title = "出库历史查询", businessType = BusinessType.DELETE)
	@DeleteMapping("/{PICKINGIDs}")
    public AjaxResult remove(@PathVariable String[] PICKINGIDs)
    {
        return toAjax(tCkPickingwavegoodsBackService.deleteTCkPickingwavegoodsBackByPICKINGIDs(PICKINGIDs));
    }
}
